/**
 * Copyright © 2011 Software in Life Inc. All rights reserved.
 */
package com.softwareinlife.restful.server.alarm.rest;

import java.util.List;
import java.util.logging.Logger;

import javax.ws.rs.DELETE;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import com.softwareinlife.restful.server.alarm.dao.AlarmJDO;
import com.softwareinlife.restful.server.alarm.model.AlarmModel;
import com.softwareinlife.restful.server.alarm.model.DatasModel;
import com.softwareinlife.restful.server.alarm.service.AlarmService;

/**
 * <b>RESTful Web Service Component for Users</b>
 * 
 * <p>
 * For a complete reference see <a href=
 * "http://jersey.java.net/nonav/documentation/latest/index.html" > Jersey 1.6
 * User Guide Documentations</a>
 * </p>
 * 
 * @author Jang, Sun-Jin(jangsunjin@softwareinlife.com)
 */
@Path("/alarm")
@Component
@Scope("request")
public class AlarmRest {

	/**
	 * Logger
	 */
	protected static Logger logger = Logger.getLogger("rest");

	/**
	 * Service
	 */
	@Autowired
	private AlarmService service;

	/**
	 * DAO
	 */
	@Autowired
	private AlarmJDO jdo;

	@POST
	@Produces({ "application/xml", "application/json" })
	@Path("/jdo/post/")
	public AlarmModel postAlarmByJDO(AlarmModel model) {
		if (model != null) {
			jdo.saveOrUpdate(model);
		}

		return model;
	}
	
	@GET
	@Produces({ "application/xml", "application/json" })
	@Path("/jdo")
	public DatasModel getAlarmByJDO() {
		DatasModel model = new DatasModel();
		List<AlarmModel> results = jdo.read();
		if (results != null) {
			model.setList(results);
		}
		
		return model;
	}
	
	@GET
	@Produces({ "application/xml", "application/json" })
	@Path("/jdo/{id}")
	public AlarmModel getAlarmByJDO(@PathParam("id") long id) {
		return jdo.read(id);
	}

	@PUT
	@Produces({ "application/xml", "application/json" })
	@Path("/jdo/put/")
	public AlarmModel putAlarmByJDO() {
		AlarmModel model = new AlarmModel();

		return model;
	}
	
	@DELETE
	@Produces({ "application/xml", "application/json" })
	@Path("/jdo/delete/{id}")
	public void deleteAlarmByJDO(@PathParam("id") long id) {
		jdo.delete(id);
	}
}
